<?php

	// +----------------------------------------------------------------------
	// | APP设备
	// +----------------------------------------------------------------------
	// | Copyright (c) 2015-2024 http://www.yicmf.com, All rights reserved.
	// +----------------------------------------------------------------------
	// | Author: 微尘 <yicmf@qq.com>
	// +----------------------------------------------------------------------

	namespace app\model\app;

	use app\model\file\Image;
    use think\model\concern\SoftDelete;

    class ExchangeCouponOrder extends Common
	{

        use SoftDelete;

		public function image()
		{
			return $this->belongsTo(Image::class)->field('id,name,save_name,driver,url,path');
		}

		public function cover()
		{
			return $this->belongsTo(Image::class,'cover_id')->field('id,name,save_name,driver,url,path');
		}


        public function getImageUrlAttr($value, $data)
        {
            if ($value)
            {
                return request()->domain() . $value;
            }else{
                return Image::where('id',$data['image_id'])->value('url');
            }
        }
		/**
		 * 新增修改
		 * @param $data
		 */
		public static function onBeforeInsert($data)
		{
            $data['ip'] = request()->ip();
		}
/**
		 * 写入修改
		 * @param $data
		 */
		public static function onBeforeWrite($data)
		{
		}

        // 类型转换
        protected $type = [
            'kami' => 'array',
            'template' => 'array',
        ];

    }
